﻿using System;
using System.Collections.Generic;
using GUITree;
using UnityEngine;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x02000536 RID: 1334
	public class TreeNodeObject : MonoBehaviour
	{
		// Token: 0x1700041B RID: 1051
		// (get) Token: 0x06002225 RID: 8741 RVA: 0x000CEFFC File Offset: 0x000CD1FC
		public TreeNode treeNode
		{
			get
			{
				return this.m_TreeNode;
			}
		}

		// Token: 0x1700041C RID: 1052
		// (get) Token: 0x06002226 RID: 8742 RVA: 0x000CF004 File Offset: 0x000CD204
		public Button buttonState
		{
			get
			{
				return this.m_ButtonState;
			}
		}

		// Token: 0x1700041D RID: 1053
		// (get) Token: 0x06002227 RID: 8743 RVA: 0x000CF00C File Offset: 0x000CD20C
		public Button buttonSelect
		{
			get
			{
				return this.m_ButtonSelect;
			}
		}

		// Token: 0x1700041E RID: 1054
		// (get) Token: 0x06002228 RID: 8744 RVA: 0x000CF014 File Offset: 0x000CD214
		public Image imageSelect
		{
			get
			{
				return this.m_ImageSelect;
			}
		}

		// Token: 0x1700041F RID: 1055
		// (set) Token: 0x06002229 RID: 8745 RVA: 0x000CF01C File Offset: 0x000CD21C
		public Color colorSelect
		{
			set
			{
				this.imageSelect.color = value;
			}
		}

		// Token: 0x17000420 RID: 1056
		// (get) Token: 0x0600222A RID: 8746 RVA: 0x000CF02C File Offset: 0x000CD22C
		// (set) Token: 0x0600222B RID: 8747 RVA: 0x000CF03C File Offset: 0x000CD23C
		public string textName
		{
			get
			{
				return this.m_TextName.text;
			}
			set
			{
				this.m_TextName.text = value;
			}
		}

		// Token: 0x17000421 RID: 1057
		// (get) Token: 0x0600222C RID: 8748 RVA: 0x000CF04C File Offset: 0x000CD24C
		// (set) Token: 0x0600222D RID: 8749 RVA: 0x000CF054 File Offset: 0x000CD254
		public TreeNodeObject.TreeState treeState
		{
			get
			{
				return this.m_TreeState;
			}
			set
			{
				if (Utility.SetStruct<TreeNodeObject.TreeState>(ref this.m_TreeState, value))
				{
					this.SetTreeState(this.m_TreeState);
				}
			}
		}

		// Token: 0x17000422 RID: 1058
		// (get) Token: 0x0600222E RID: 8750 RVA: 0x000CF074 File Offset: 0x000CD274
		public Image imageState
		{
			get
			{
				if (this.m_ImageState == null)
				{
					this.m_ImageState = this.m_ButtonState.GetComponent<Image>();
				}
				return this.m_ImageState;
			}
		}

		// Token: 0x17000423 RID: 1059
		// (get) Token: 0x0600222F RID: 8751 RVA: 0x000CF0A0 File Offset: 0x000CD2A0
		// (set) Token: 0x06002230 RID: 8752 RVA: 0x000CF0A8 File Offset: 0x000CD2A8
		public bool visible
		{
			get
			{
				return this.m_Visible;
			}
			set
			{
				this.SetVisible(value);
			}
		}

		// Token: 0x17000424 RID: 1060
		// (get) Token: 0x06002231 RID: 8753 RVA: 0x000CF0B4 File Offset: 0x000CD2B4
		public Button buttonVisible
		{
			get
			{
				return this.m_ButtonVisible;
			}
		}

		// Token: 0x17000425 RID: 1061
		// (get) Token: 0x06002232 RID: 8754 RVA: 0x000CF0BC File Offset: 0x000CD2BC
		public Image imageVisible
		{
			get
			{
				if (this.m_ImageVisible == null)
				{
					this.m_ImageVisible = this.m_ButtonVisible.image;
				}
				return this.m_ImageVisible;
			}
		}

		// Token: 0x17000426 RID: 1062
		// (set) Token: 0x06002233 RID: 8755 RVA: 0x000CF0E8 File Offset: 0x000CD2E8
		public bool enableVisible
		{
			set
			{
				this.m_ButtonVisible.gameObject.SetActive(value);
				Vector2 anchoredPosition = this.m_TransSelect.anchoredPosition;
				anchoredPosition.x = (float)((!value) ? 16 : 32);
				this.m_TransSelect.anchoredPosition = anchoredPosition;
			}
		}

		// Token: 0x17000427 RID: 1063
		// (get) Token: 0x06002234 RID: 8756 RVA: 0x000CF138 File Offset: 0x000CD338
		// (set) Token: 0x06002235 RID: 8757 RVA: 0x000CF140 File Offset: 0x000CD340
		public TreeNodeObject parent { get; set; }

		// Token: 0x17000428 RID: 1064
		// (get) Token: 0x06002236 RID: 8758 RVA: 0x000CF14C File Offset: 0x000CD34C
		public bool isParent
		{
			get
			{
				return this.parent != null && this.enableChangeParent;
			}
		}

		// Token: 0x17000429 RID: 1065
		// (get) Token: 0x06002237 RID: 8759 RVA: 0x000CF168 File Offset: 0x000CD368
		public int childCount
		{
			get
			{
				return this.m_child.Count;
			}
		}

		// Token: 0x1700042A RID: 1066
		// (get) Token: 0x06002238 RID: 8760 RVA: 0x000CF178 File Offset: 0x000CD378
		public List<TreeNodeObject> child
		{
			get
			{
				return this.m_child;
			}
		}

		// Token: 0x1700042B RID: 1067
		// (get) Token: 0x06002239 RID: 8761 RVA: 0x000CF180 File Offset: 0x000CD380
		// (set) Token: 0x0600223A RID: 8762 RVA: 0x000CF188 File Offset: 0x000CD388
		public bool enableChangeParent { get; set; }

		// Token: 0x1700042C RID: 1068
		// (get) Token: 0x0600223B RID: 8763 RVA: 0x000CF194 File Offset: 0x000CD394
		// (set) Token: 0x0600223C RID: 8764 RVA: 0x000CF19C File Offset: 0x000CD39C
		public bool enableDelete { get; set; }

		// Token: 0x1700042D RID: 1069
		// (get) Token: 0x0600223D RID: 8765 RVA: 0x000CF1A8 File Offset: 0x000CD3A8
		// (set) Token: 0x0600223E RID: 8766 RVA: 0x000CF1B0 File Offset: 0x000CD3B0
		public bool enableAddChild { get; set; }

		// Token: 0x1700042E RID: 1070
		// (get) Token: 0x0600223F RID: 8767 RVA: 0x000CF1BC File Offset: 0x000CD3BC
		// (set) Token: 0x06002240 RID: 8768 RVA: 0x000CF1C4 File Offset: 0x000CD3C4
		public bool enableCopy { get; set; }

		// Token: 0x1700042F RID: 1071
		// (get) Token: 0x06002241 RID: 8769 RVA: 0x000CF1D0 File Offset: 0x000CD3D0
		// (set) Token: 0x06002242 RID: 8770 RVA: 0x000CF1D8 File Offset: 0x000CD3D8
		public Color baseColor { get; set; }

		// Token: 0x06002243 RID: 8771 RVA: 0x000CF1E4 File Offset: 0x000CD3E4
		public void OnClickState()
		{
			SortCanvas.select = this.canvas;
			this.SetTreeState((this.m_TreeState != TreeNodeObject.TreeState.Open) ? TreeNodeObject.TreeState.Open : TreeNodeObject.TreeState.Close);
		}

		// Token: 0x06002244 RID: 8772 RVA: 0x000CF20C File Offset: 0x000CD40C
		public void OnClickSelect()
		{
			SortCanvas.select = this.canvas;
			this.m_TreeNodeCtrl.selectNode = this;
		}

		// Token: 0x06002245 RID: 8773 RVA: 0x000CF228 File Offset: 0x000CD428
		public void OnClickVisible()
		{
			SortCanvas.select = this.canvas;
			this.SetVisible(!this.m_Visible);
		}

		// Token: 0x06002246 RID: 8774 RVA: 0x000CF244 File Offset: 0x000CD444
		public void OnDeselect()
		{
			this.colorSelect = this.baseColor;
			ObjectCtrlInfo objectCtrlInfo = null;
			if (Singleton<Studio>.Instance.dicInfo.TryGetValue(this, out objectCtrlInfo))
			{
				objectCtrlInfo.guideObject.SetActive(false, true);
			}
		}

		// Token: 0x06002247 RID: 8775 RVA: 0x000CF284 File Offset: 0x000CD484
		public bool SetParent(TreeNodeObject _parent)
		{
			if (!this.enableChangeParent)
			{
				return false;
			}
			if (this.CheckParentLoop(_parent, this))
			{
				return false;
			}
			if (_parent && (_parent.child.Contains(this) || !_parent.enableAddChild))
			{
				return false;
			}
			if (this.parent != null)
			{
				this.parent.RemoveChild(this);
			}
			if (_parent)
			{
				_parent.AddChild(this);
			}
			else
			{
				this.parent = null;
				this.m_TreeNodeCtrl.AddNode(this);
			}
			return true;
		}

		// Token: 0x06002248 RID: 8776 RVA: 0x000CF320 File Offset: 0x000CD520
		public bool AddChild(TreeNodeObject _child)
		{
			if (!this.enableAddChild)
			{
				return false;
			}
			if (_child == null || _child == this)
			{
				return false;
			}
			if (this.m_child.Contains(_child))
			{
				return false;
			}
			this.m_child.Add(_child);
			_child.parent = this;
			this.m_TreeNodeCtrl.RemoveNode(_child);
			this.SetStateVisible(true);
			this.SetTreeState(this.m_TreeState);
			return true;
		}

		// Token: 0x06002249 RID: 8777 RVA: 0x000CF39C File Offset: 0x000CD59C
		public void RemoveChild(TreeNodeObject _child)
		{
			_child.transform.SetAsLastSibling();
			this.m_child.Remove(_child);
			_child.parent = null;
			this.m_TreeNodeCtrl.AddNode(_child);
			this.SetStateVisible(this.childCount != 0);
		}

		// Token: 0x0600224A RID: 8778 RVA: 0x000CF3DC File Offset: 0x000CD5DC
		public void SetTreeState(TreeNodeObject.TreeState _state)
		{
			this.m_TreeState = _state;
			this.imageState.sprite = this.m_SpriteState[(int)_state];
			int childCount = this.childCount;
			bool visible = _state == TreeNodeObject.TreeState.Open;
			for (int i = 0; i < childCount; i++)
			{
				this.SetVisibleLoop(this.m_child[i], visible);
			}
		}

		// Token: 0x0600224B RID: 8779 RVA: 0x000CF434 File Offset: 0x000CD634
		public void SetVisible(bool _visible)
		{
			this.m_Visible = _visible;
			if (this.onVisible != null)
			{
				this.onVisible(_visible);
			}
			this.imageVisible.sprite = this.m_SpriteVisible[(!_visible) ? 0 : 1];
			int childCount = this.childCount;
			for (int i = 0; i < childCount; i++)
			{
				this.SetVisibleChild(this.m_child[i], _visible);
			}
		}

		// Token: 0x0600224C RID: 8780 RVA: 0x000CF4AC File Offset: 0x000CD6AC
		protected void SetStateVisible(bool _visible)
		{
			if (this.m_ButtonState)
			{
				this.m_ButtonState.gameObject.SetActive(_visible);
			}
		}

		// Token: 0x0600224D RID: 8781 RVA: 0x000CF4D0 File Offset: 0x000CD6D0
		protected void SetVisibleLoop(TreeNodeObject _source, bool _visible)
		{
			if (_source.gameObject.activeSelf != _visible)
			{
				_source.gameObject.SetActive(_visible);
			}
			if (_visible && _source.treeState == TreeNodeObject.TreeState.Close)
			{
				_visible = false;
			}
			int childCount = _source.childCount;
			for (int i = 0; i < childCount; i++)
			{
				this.SetVisibleLoop(_source.child[i], _visible);
			}
		}

		// Token: 0x0600224E RID: 8782 RVA: 0x000CF53C File Offset: 0x000CD73C
		protected bool CheckParentLoop(TreeNodeObject _source, TreeNodeObject _target)
		{
			return !(_source == null) && (_source == _target || this.CheckParentLoop(_source.parent, _target));
		}

		// Token: 0x0600224F RID: 8783 RVA: 0x000CF568 File Offset: 0x000CD768
		protected void SetVisibleChild(TreeNodeObject _source, bool _visible)
		{
			bool flag = (!_visible || _source.visible) && _visible;
			if (_source.onVisible != null)
			{
				_source.onVisible(flag);
			}
			_source.buttonVisible.interactable = _visible;
			int childCount = _source.childCount;
			for (int i = 0; i < childCount; i++)
			{
				this.SetVisibleChild(_source.child[i], flag);
			}
		}

		// Token: 0x06002250 RID: 8784 RVA: 0x000CF5E0 File Offset: 0x000CD7E0
		private void Awake()
		{
			this.enableChangeParent = true;
			this.enableDelete = true;
			this.enableAddChild = true;
			this.enableCopy = true;
			this.baseColor = Utility.ConvertColor(100, 99, 94);
			this.colorSelect = this.baseColor;
		}

		// Token: 0x06002251 RID: 8785 RVA: 0x000CF61C File Offset: 0x000CD81C
		private void Start()
		{
			this.SetStateVisible(this.childCount != 0);
		}

		// Token: 0x04002352 RID: 9042
		[SerializeField]
		protected TreeNode m_TreeNode;

		// Token: 0x04002353 RID: 9043
		[SerializeField]
		protected Sprite[] m_SpriteState;

		// Token: 0x04002354 RID: 9044
		[SerializeField]
		protected Button m_ButtonState;

		// Token: 0x04002355 RID: 9045
		[SerializeField]
		protected Button m_ButtonSelect;

		// Token: 0x04002356 RID: 9046
		[SerializeField]
		protected Image m_ImageSelect;

		// Token: 0x04002357 RID: 9047
		[SerializeField]
		protected RectTransform m_TransSelect;

		// Token: 0x04002358 RID: 9048
		[SerializeField]
		protected Text m_TextName;

		// Token: 0x04002359 RID: 9049
		[SerializeField]
		protected Canvas canvas;

		// Token: 0x0400235A RID: 9050
		protected TreeNodeObject.TreeState m_TreeState;

		// Token: 0x0400235B RID: 9051
		protected Image m_ImageState;

		// Token: 0x0400235C RID: 9052
		[SerializeField]
		protected TreeNodeCtrl m_TreeNodeCtrl;

		// Token: 0x0400235D RID: 9053
		protected bool m_Visible = true;

		// Token: 0x0400235E RID: 9054
		[SerializeField]
		protected Button m_ButtonVisible;

		// Token: 0x0400235F RID: 9055
		protected Image m_ImageVisible;

		// Token: 0x04002360 RID: 9056
		[SerializeField]
		protected Sprite[] m_SpriteVisible;

		// Token: 0x04002361 RID: 9057
		public TreeNodeObject.OnVisibleFunc onVisible;

		// Token: 0x04002363 RID: 9059
		protected List<TreeNodeObject> m_child = new List<TreeNodeObject>();

		// Token: 0x02000537 RID: 1335
		public enum TreeState
		{
			// Token: 0x0400236A RID: 9066
			Open,
			// Token: 0x0400236B RID: 9067
			Close
		}

		// Token: 0x02000538 RID: 1336
		// (Invoke) Token: 0x06002253 RID: 8787
		public delegate void OnVisibleFunc(bool _b);
	}
}
